package com.yundingai.mapper;

import com.yundingai.domain.entity.RelStudyInfoSubject;
import com.yundingai.domain.entity.StudyInfo;
import com.yundingai.domain.entity.Subject;
import com.yundingai.domain.entity.vo.ReceiveSubjectListVo;
import com.yundingai.domain.entity.vo.StudyInfoVo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface StudyInfoMapper {
    // 插入学习信息，多条件插入
    void insertStudyInfo(ReceiveSubjectListVo receiveSubjectListVo);
    // 根据用户ID查询学习信息
    @Select("select * from study_info where user_id = #{userId}")
    StudyInfo selectStudyInfoByUserId(Integer userId);
    // 更新学习信息
    void updateStudyInfo(ReceiveSubjectListVo receiveSubjectListVo);
    // 删除学习信息
//    void deleteStudyInfo(Integer studyInfoId);

    //在中间表rel_subject_info中插入一条数据
    @Insert("insert into rel_subject_info (studyInfo_id, subject_id) values (#{studyInfoId}, #{subjectId})")
    void insertRelSubjectInfo(Integer studyInfoId, Integer subjectId);


    //连表查询学习信息表和学科表，映射在前端ui

    StudyInfo selectStudyInfoVoByUserId(Integer userId);

    //根据userId查询学习信息表中的studyinfo_id，，然后拿到studyinfo_id去查询中间表，
    // 获取subject_id，再通过subject_id查询学科表，最后，先删学科表，再删中间表，顺序必须按照这个来
    //selectStudyInfoVoByUserId直接使用这个方法，因为前端已经使用这个方法获取到了userid的值，直接使用就行

@Select("select * from rel_subject_info where studyInfo_id = #{studyInfoId}")
   List<RelStudyInfoSubject> selectRelSubjectInfoByInfoId(Integer studyInfoId);

@Select("select * from study_subject where subject_id = #{subjectId}")
    Subject selectSubjectBySubjectId(Integer subjectId);

//删除学科信息表中的数据
    @Delete("delete from study_subject where subject_id = #{subjectId}")
    void deleteSubject(Integer subjectId);
//删除中间表中的数据
    @Delete("delete from rel_subject_info where studyInfo_id = #{studyInfoId}")
    void deleteRelSubjectInfo(Integer studyInfoId);



//根据subject_id查询学科表，获取学科名，然后修改学科表中学科名称
    @Update("update study_subject set subject_name = #{subjectName} where subject_id = #{subjectId}")
    void updateSubjectName(String subjectName,Integer subjectId);


//向学科表中插入数据
    @Insert("insert into study_subject(subject_name) values(#{subjectName})")
    @Options(useGeneratedKeys = true,keyProperty = "subjectId")
    void insertSubject(Subject subject);

}
